﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Text;

namespace RB.Utility
{
    public static class NameValueCollectionExtensions
    {
        public static void SetReadOnlyItemValue(this NameValueCollection collection, string name, string value)
        {
            PropertyInfo readOnlyInfo = collection.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
            readOnlyInfo.SetValue(collection, false, null);
            collection[name] = value;
            readOnlyInfo.SetValue(collection, true, null);
        }
    }
}
